/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CourseDetail.java
 *
 * Created on 26-03-2012, 22:48:43
 */
package Management;

import UploadData.Database;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author s0lo
 */
public class CourseDetail extends javax.swing.JFrame {

    private int CRID;
    private int StuID;
    private int CourID;
    public String Access;
    private Vector vtSubjectDetail;
    private Vector vtMark;
    private Vector vtPayment;
    private Vector vtPaymentType;

    /** Creates new form CourseDetail */
    public CourseDetail(int crID, int stuID, int courID, String access) {
        initComponents();
        this.CRID = crID;
        this.StuID = stuID;
        this.CourID = courID;
        this.Access = access;
        this.setVisible(true);
        initSubject();
        initPaymentType();
        loadMark();
        loadPayment();
        if (access.equals("0")) {
            btnInsertMark.setVisible(false);
            btnUpdateMark.setVisible(false);
            btnDeleteMark.setVisible(false);
            btnRefreshMark.setVisible(false);
            btnInsertPayment.setVisible(false);
            btnUpdatePayment.setVisible(false);
            btnDeletePayment.setVisible(false);
            btnRefreshPayment.setVisible(false);
            cbbPaymentType.setEnabled(false);
            cbbSubject.setEnabled(false);
            txtMark.setEnabled(false);
            txtPaid.setEnabled(false);
            chkSuccessful.setEnabled(false);
            chkUnsuccessful.setEnabled(false);
            txtBalance.setEnabled(false);
        }
    }

    public void initPaymentType() {
        vtPaymentType = new Database().loadPaymentType(" order by TypeName");
        Vector vtCount = new Vector();
        vtCount.add("choose");
        for (int i = 0; i < vtPaymentType.size(); i++) {
            Vector vttem = (Vector) vtPaymentType.get(i);
            vtCount.add(vttem.get(1).toString());
        }
        if (vtCount.size() == 0) {
            vtPaymentType.add("Please click here!");
        }
        DefaultComboBoxModel dcbm = new DefaultComboBoxModel(vtCount);
        cbbPaymentType.setModel(dcbm);
        cbbPaymentType.setSelectedItem("Select All");
    }

    public void loadPayment() {
        vtPayment = new Database().loadvwPayment(" where CourseID=" + CourID + " and StuID=" + StuID + " order by Times");
        if (vtPayment.size() != 0) {
            Vector vtCol = new Vector();
            Vector vtDisplay = new Vector();
            for (int i = 0; i < vtPayment.size(); i++) {

                vtCol.add(((Vector) vtPayment.get(i)).get(4).toString());
                vtCol.add(((Vector) vtPayment.get(i)).get(6).toString());
                vtCol.add(((Vector) vtPayment.get(i)).get(7).toString());
                vtCol.add(((Vector) vtPayment.get(i)).get(8).toString());
                vtCol.add(((Vector) vtPayment.get(i)).get(9).toString());
                vtCol.add(((Vector) vtPayment.get(i)).get(10).toString());
                vtCol.add(((Vector) vtPayment.get(i)).get(11).toString());
                String Status = ((Vector) vtPayment.get(i)).get(12).toString();
                if (Status.trim().equals("1")) {
                    Status = "Successful";
                } else if (Status.equals("0")) {
                    Status = "Unsuccessful";
                }
                vtCol.add(Status);
                vtDisplay.add(vtCol);
                vtCol = new Vector();
            }
            for (int i = 0; i < ((Vector) vtDisplay.get(0)).size(); i++) {
                vtCol.add("Col " + (i + 1));
            }
            vtCol = new Vector();
            vtCol.add("Course Name ");
            vtCol.add("Payment Type");
            vtCol.add("Total Fees");
            vtCol.add(" Paid ");
            vtCol.add(" Balance ");
            vtCol.add(" Times ");
            vtCol.add("Payment Date");
            vtCol.add("Status");
            DefaultTableModel dtm = new DefaultTableModel(vtDisplay, vtCol);
            tbPayment.setModel(dtm);
        }
    }

    public void initSubject() {
        vtSubjectDetail = new Database().loadSubjectDetail(" where CourseID=" + CourID);
        Vector vtCount = new Vector();
        vtCount.add("choose");
        for (int i = 0; i < vtSubjectDetail.size(); i++) {
            Vector vttem = (Vector) vtSubjectDetail.get(i);
            int SubID = Integer.parseInt(vttem.get(0).toString());
            String subName = "";
            Vector vtSubject = new Database().loadSubject(" where SubID=" + SubID);
            if (vtSubject.size() > 0) {
                int subID;
                for (int j = 0; j < vtSubject.size(); j++) {
                    subID = Integer.parseInt(((Vector) vtSubject.get(j)).get(0).toString());
                    if (subID == SubID) {
                        subName = ((Vector) vtSubject.get(j)).get(1).toString();
                    }
                }
            }
            vtCount.add(subName);
        }
        if (vtCount.size() == 0) {
            vtSubjectDetail.add("Please click here!");
        }
        DefaultComboBoxModel dcbm = new DefaultComboBoxModel(vtCount);
        cbbSubject.setModel(dcbm);
        cbbSubject.setSelectedItem("Select All");
    }

    public void loadMark() {
        vtMark = new Database().loadvwCourseDetail(" where CourseID=" + CourID + " and StuID=" + StuID + " order by SubID");
        if (vtMark.size() != 0) {
            Vector vtCol = new Vector();
            Vector vtDisplay = new Vector();
            for (int i = 0; i < vtMark.size(); i++) {

                vtCol.add(((Vector) vtMark.get(i)).get(5).toString());
                vtCol.add(((Vector) vtMark.get(i)).get(6).toString());
                vtCol.add(((Vector) vtMark.get(i)).get(7).toString());
                vtCol.add(((Vector) vtMark.get(i)).get(8).toString());
                String Status = ((Vector) vtMark.get(i)).get(9).toString();
                if (Status.trim().equals("0")) {
                    Status = "Fail";
                } else if (Status.equals("1")) {
                    Status = "Pass";
                }
                vtCol.add(Status);
                vtDisplay.add(vtCol);
                vtCol = new Vector();
            }
            for (int i = 0; i < ((Vector) vtDisplay.get(0)).size(); i++) {
                vtCol.add("Col " + (i + 1));
            }
            vtCol = new Vector();
            vtCol.add("Course Name ");
            vtCol.add("subject Name");
            vtCol.add(" Mark ");
            vtCol.add("Time");
            vtCol.add("Status");
            DefaultTableModel dtm = new DefaultTableModel(vtDisplay, vtCol);
            tbMark.setModel(dtm);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        panAcademic = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        cbbSubject = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        btnUpdateMark = new javax.swing.JButton();
        txtTime = new javax.swing.JTextField();
        jScrollPane3 = new javax.swing.JScrollPane();
        tbMark = new javax.swing.JTable();
        btnRefreshMark = new javax.swing.JButton();
        btnInsertMark = new javax.swing.JButton();
        btnDeleteMark = new javax.swing.JButton();
        txtMark = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        chkPass = new javax.swing.JRadioButton();
        chkFail = new javax.swing.JRadioButton();
        jPanel2 = new javax.swing.JPanel();
        panAcademic1 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        cbbPaymentType = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        btnUpdatePayment = new javax.swing.JButton();
        txtPaid = new javax.swing.JTextField();
        jScrollPane4 = new javax.swing.JScrollPane();
        tbPayment = new javax.swing.JTable();
        btnRefreshPayment = new javax.swing.JButton();
        btnInsertPayment = new javax.swing.JButton();
        btnDeletePayment = new javax.swing.JButton();
        txtTimes = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        chkSuccessful = new javax.swing.JRadioButton();
        chkUnsuccessful = new javax.swing.JRadioButton();
        jLabel14 = new javax.swing.JLabel();
        txtBalance = new javax.swing.JTextField();
        btnSignOut = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(204, 255, 204));

        panAcademic.setBackground(new java.awt.Color(204, 255, 204));

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel8.setForeground(new java.awt.Color(0, 0, 51));
        jLabel8.setText("Mark :");

        cbbSubject.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbbSubjectItemStateChanged(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel9.setForeground(new java.awt.Color(0, 0, 51));
        jLabel9.setText("Time: ");

        btnUpdateMark.setFont(new java.awt.Font("Tahoma", 1, 11));
        btnUpdateMark.setForeground(new java.awt.Color(0, 0, 51));
        btnUpdateMark.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/save.png"))); // NOI18N
        btnUpdateMark.setText("Update");
        btnUpdateMark.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateMarkActionPerformed(evt);
            }
        });

        txtTime.setEnabled(false);

        tbMark.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tbMark.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbMarkMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(tbMark);

        btnRefreshMark.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnRefreshMark.setForeground(new java.awt.Color(0, 0, 51));
        btnRefreshMark.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/restart.jpg"))); // NOI18N
        btnRefreshMark.setText("Cancel");
        btnRefreshMark.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefreshMarkActionPerformed(evt);
            }
        });

        btnInsertMark.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnInsertMark.setForeground(new java.awt.Color(0, 0, 51));
        btnInsertMark.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/add.png"))); // NOI18N
        btnInsertMark.setText("Insert");
        btnInsertMark.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInsertMarkActionPerformed(evt);
            }
        });

        btnDeleteMark.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnDeleteMark.setForeground(new java.awt.Color(0, 0, 51));
        btnDeleteMark.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/del.png"))); // NOI18N
        btnDeleteMark.setText("Delete");
        btnDeleteMark.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteMarkActionPerformed(evt);
            }
        });

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel10.setForeground(new java.awt.Color(0, 0, 51));
        jLabel10.setText("Subject");

        jPanel3.setBackground(new java.awt.Color(204, 255, 204));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Status", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N
        jPanel3.setForeground(new java.awt.Color(0, 0, 51));

        chkPass.setBackground(new java.awt.Color(204, 255, 204));
        buttonGroup1.add(chkPass);
        chkPass.setFont(new java.awt.Font("Tahoma", 1, 11));
        chkPass.setForeground(new java.awt.Color(0, 0, 51));
        chkPass.setText("Pass");
        chkPass.setEnabled(false);

        chkFail.setBackground(new java.awt.Color(204, 255, 204));
        buttonGroup1.add(chkFail);
        chkFail.setFont(new java.awt.Font("Tahoma", 1, 11));
        chkFail.setForeground(new java.awt.Color(0, 0, 51));
        chkFail.setText("Fail");
        chkFail.setEnabled(false);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(62, Short.MAX_VALUE)
                .addComponent(chkPass)
                .addGap(49, 49, 49)
                .addComponent(chkFail)
                .addGap(79, 79, 79))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(chkPass)
                .addComponent(chkFail))
        );

        javax.swing.GroupLayout panAcademicLayout = new javax.swing.GroupLayout(panAcademic);
        panAcademic.setLayout(panAcademicLayout);
        panAcademicLayout.setHorizontalGroup(
            panAcademicLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panAcademicLayout.createSequentialGroup()
                .addGroup(panAcademicLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panAcademicLayout.createSequentialGroup()
                        .addGap(92, 92, 92)
                        .addGroup(panAcademicLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panAcademicLayout.createSequentialGroup()
                                .addComponent(btnInsertMark, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnUpdateMark, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnDeleteMark, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnRefreshMark))
                            .addGroup(panAcademicLayout.createSequentialGroup()
                                .addGroup(panAcademicLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel10)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel8))
                                .addGap(21, 21, 21)
                                .addGroup(panAcademicLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtMark)
                                    .addComponent(txtTime)
                                    .addComponent(cbbSubject, 0, 227, Short.MAX_VALUE)))
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(panAcademicLayout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 561, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(52, Short.MAX_VALUE))
        );
        panAcademicLayout.setVerticalGroup(
            panAcademicLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panAcademicLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(panAcademicLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(cbbSubject, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17)
                .addGroup(panAcademicLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtMark, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(panAcademicLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
                .addGroup(panAcademicLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnInsertMark, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnUpdateMark, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnDeleteMark, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnRefreshMark, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 649, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(panAcademic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 515, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(panAcademic, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("    Mark   ", jPanel1);

        panAcademic1.setBackground(new java.awt.Color(204, 255, 204));

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel11.setForeground(new java.awt.Color(0, 0, 51));
        jLabel11.setText("Times : ");

        cbbPaymentType.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbbPaymentTypeItemStateChanged(evt);
            }
        });

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel12.setForeground(new java.awt.Color(0, 0, 51));
        jLabel12.setText("Paid :");

        btnUpdatePayment.setFont(new java.awt.Font("Tahoma", 1, 11));
        btnUpdatePayment.setForeground(new java.awt.Color(0, 0, 51));
        btnUpdatePayment.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/save.png"))); // NOI18N
        btnUpdatePayment.setText("Update");
        btnUpdatePayment.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdatePaymentActionPerformed(evt);
            }
        });

        tbPayment.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tbPayment.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbPaymentMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(tbPayment);

        btnRefreshPayment.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnRefreshPayment.setForeground(new java.awt.Color(0, 0, 51));
        btnRefreshPayment.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/restart.jpg"))); // NOI18N
        btnRefreshPayment.setText("Cancel");
        btnRefreshPayment.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefreshPaymentActionPerformed(evt);
            }
        });

        btnInsertPayment.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnInsertPayment.setForeground(new java.awt.Color(0, 0, 51));
        btnInsertPayment.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/add.png"))); // NOI18N
        btnInsertPayment.setText("Insert");
        btnInsertPayment.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInsertPaymentActionPerformed(evt);
            }
        });

        btnDeletePayment.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnDeletePayment.setForeground(new java.awt.Color(0, 0, 51));
        btnDeletePayment.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/del.png"))); // NOI18N
        btnDeletePayment.setText("Delete");
        btnDeletePayment.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeletePaymentActionPerformed(evt);
            }
        });

        txtTimes.setEnabled(false);

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel13.setForeground(new java.awt.Color(0, 0, 51));
        jLabel13.setText("Payment Type :");

        jPanel4.setBackground(new java.awt.Color(204, 255, 204));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Status", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N
        jPanel4.setForeground(new java.awt.Color(0, 0, 51));

        chkSuccessful.setBackground(new java.awt.Color(204, 255, 204));
        buttonGroup2.add(chkSuccessful);
        chkSuccessful.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        chkSuccessful.setForeground(new java.awt.Color(0, 0, 51));
        chkSuccessful.setText("Successful");

        chkUnsuccessful.setBackground(new java.awt.Color(204, 255, 204));
        buttonGroup2.add(chkUnsuccessful);
        chkUnsuccessful.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        chkUnsuccessful.setForeground(new java.awt.Color(0, 0, 51));
        chkUnsuccessful.setText("Unsuccessful");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(62, Short.MAX_VALUE)
                .addComponent(chkSuccessful)
                .addGap(49, 49, 49)
                .addComponent(chkUnsuccessful)
                .addGap(79, 79, 79))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(chkSuccessful)
                .addComponent(chkUnsuccessful))
        );

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel14.setForeground(new java.awt.Color(0, 0, 51));
        jLabel14.setText("Balance :");

        javax.swing.GroupLayout panAcademic1Layout = new javax.swing.GroupLayout(panAcademic1);
        panAcademic1.setLayout(panAcademic1Layout);
        panAcademic1Layout.setHorizontalGroup(
            panAcademic1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panAcademic1Layout.createSequentialGroup()
                .addGroup(panAcademic1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panAcademic1Layout.createSequentialGroup()
                        .addGap(92, 92, 92)
                        .addGroup(panAcademic1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panAcademic1Layout.createSequentialGroup()
                                .addComponent(btnInsertPayment, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnUpdatePayment, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnDeletePayment, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnRefreshPayment))
                            .addGroup(panAcademic1Layout.createSequentialGroup()
                                .addGroup(panAcademic1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel13)
                                    .addComponent(jLabel12)
                                    .addComponent(jLabel11)
                                    .addComponent(jLabel14))
                                .addGap(21, 21, 21)
                                .addGroup(panAcademic1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtBalance)
                                    .addComponent(txtTimes)
                                    .addComponent(txtPaid)
                                    .addComponent(cbbPaymentType, 0, 227, Short.MAX_VALUE)))
                            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(panAcademic1Layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 561, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(35, 35, 35))
        );
        panAcademic1Layout.setVerticalGroup(
            panAcademic1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panAcademic1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(panAcademic1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(cbbPaymentType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17)
                .addGroup(panAcademic1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtTimes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(panAcademic1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(txtPaid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(panAcademic1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(txtBalance, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(panAcademic1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnInsertPayment, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnUpdatePayment, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnDeletePayment, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnRefreshPayment, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 649, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addComponent(panAcademic1, javax.swing.GroupLayout.PREFERRED_SIZE, 640, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 515, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addComponent(panAcademic1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        jTabbedPane1.addTab("     Payment    ", jPanel2);

        btnSignOut.setFont(new java.awt.Font("Tahoma", 1, 11));
        btnSignOut.setForeground(new java.awt.Color(0, 0, 51));
        btnSignOut.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/close1.png"))); // NOI18N
        btnSignOut.setText("Exit");
        btnSignOut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSignOutonSignOut(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(483, Short.MAX_VALUE)
                .addComponent(btnSignOut)
                .addGap(94, 94, 94))
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 654, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(btnSignOut, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSignOutonSignOut(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSignOutonSignOut
        // TODO add your handling code here:
        int yes = JOptionPane.showConfirmDialog(this, "Are you sure you want to Exit?", "Exit confirm", JOptionPane.YES_NO_OPTION);
        if (yes == 0) {
            this.dispose();
        }
    }//GEN-LAST:event_btnSignOutonSignOut

    private void cbbSubjectItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbbSubjectItemStateChanged
        // TODO add your handling code here:
        /*
        String strSpl = cbDiploma.getSelectedItem().toString();
        if (strSpl.equals("other")) {
        String newdip = JOptionPane.showInputDialog(this, "Please name of new Diploma!");
        new Database().addDiploma(newdip);
        initDiploma();
        parent.loadDiploma();
        parent.initDiploma();
        cbDiploma.setSelectedItem(newdip);
        }
         *
         */
}//GEN-LAST:event_cbbSubjectItemStateChanged

    private void btnUpdateMarkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateMarkActionPerformed
        // TODO add your handling code here:
        btnUpdateMark.setText("Save");
        if (btnUpdateMark.getText().equals("Save")) {
            boolean valid = validateInformationMark();
            if (valid) {
                int rscurrent = tbMark.getSelectedRow();
                if (rscurrent >= 0) {
                    String SubN;
                    int SubID = 0;
                    Vector vtSub = new Database().loadSubject("");
                    for (int i = 0; i < vtSub.size(); i++) {
                        SubN = ((Vector) vtSub.get(i)).get(1).toString();
                        if (cbbSubject.getSelectedItem().toString().equals(SubN)) {
                            SubID = Integer.parseInt(((Vector) vtSub.get(i)).get(0).toString());
                            break;
                        }
                    }
                    float Mark = Float.parseFloat(txtMark.getText());
                    int Status;
                    if (Mark >= 4) {
                        Status = 1;
                    } else {
                        Status = 0;
                    }
                    int Times = Integer.parseInt(txtTime.getText());
                    Vector vtCount = new Database().loadMarks(" where StuID=" + StuID + " and Mark="
                            + Mark + " and SubID=" + SubID + " and Times=" + Times + " and Status=" + Status);
                    if (vtCount.size() <= 0) {
                        int kq = new Database().UpdateMark(StuID, SubID, Mark, Times, Status);
                        if (kq != -1) {
                            JOptionPane.showMessageDialog(this, "Update successful!");
                            btnUpdateMark.setText("Update");
                            loadMark();
                        } else {
                            btnUpdateMark.setText("Save");
                        }
                    } else {
                        JOptionPane.showMessageDialog(this, "Mark was exist!");
                    }

                } else {
                    JOptionPane.showMessageDialog(this, "choose row you want update");
                }
            }
        }
}//GEN-LAST:event_btnUpdateMarkActionPerformed

    private void tbMarkMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbMarkMouseClicked
        // TODO add your handling code here:

        vtMark = new Database().loadvwCourseDetail(" where CourseID=" + CourID + " and StuID=" + StuID + " order by SubID");
        int rscurrent = tbMark.getSelectedRow();
        if (rscurrent >= 0) {
            Vector vtM = (Vector) vtMark.get(rscurrent);
            cbbSubject.setSelectedItem(vtM.get(6).toString());
            txtMark.setText(vtM.get(7).toString());
            txtTime.setText(vtM.get(8).toString());
            String Status = vtM.get(9).toString();
            if (Status.trim().equals("0")) {
                chkFail.setSelected(true);
            } else if (Status.equals("1")) {
                chkPass.setSelected(true);
            }
        }

}//GEN-LAST:event_tbMarkMouseClicked

    private void btnRefreshMarkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshMarkActionPerformed
        // TODO add your handling code here:
        txtMark.setText("");
        txtTime.setText("");
        btnUpdateMark.setText("Update");
        btnInsertMark.setText("Insert");
        btnUpdateMark.setVisible(true);
        cbbSubject.setSelectedIndex(0);
}//GEN-LAST:event_btnRefreshMarkActionPerformed

    private void btnInsertMarkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInsertMarkActionPerformed
        // TODO add your handling code here:

        btnInsertMark.setText("Save");
        if (btnInsertMark.getText().equals("Save")) {
            boolean valid = validateInformationMark();
            if (valid) {
                String SubN;
                int SubID = 0;
                Vector vtSub = new Database().loadSubject("");
                for (int i = 0; i < vtSub.size(); i++) {
                    SubN = ((Vector) vtSub.get(i)).get(1).toString();
                    if (cbbSubject.getSelectedItem().toString().equals(SubN)) {
                        SubID = Integer.parseInt(((Vector) vtSub.get(i)).get(0).toString());
                        break;
                    }
                }
                float Mark = Float.parseFloat(txtMark.getText());
                int Status;
                if (Mark >= 4) {
                    Status = 1;
                } else {
                    Status = 0;
                }
                int Times = 0;
                Vector vtCount = new Database().loadMarks(" where StuID=" + StuID + " and SubID=" + SubID);
                if (vtCount.size() < 5) {
                    Times = vtCount.size() + 1;
                    int kq1 = new Database().UpdateMarkStatus(StuID, SubID);
                    int kq = new Database().addMarks(StuID, SubID, Mark, Times, Status);
                    if (kq != -1) {
                        JOptionPane.showMessageDialog(this, "insert successful!");
                        loadMark();
                        btnInsertMark.setText("Insert");
                    } else {
                        btnInsertMark.setText("Save");
                    }
                } else {
                    JOptionPane.showMessageDialog(this, "add Mark Error !");
                }

                //  }
            }
        }
}//GEN-LAST:event_btnInsertMarkActionPerformed

    private void btnDeleteMarkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteMarkActionPerformed
        // TODO add your handling code here:

        vtMark = new Database().loadvwCourseDetail(" where CourseID=" + CourID + " order by SubID");
        int rscurrent = tbMark.getSelectedRow();
        if (rscurrent >= 0) {
            if (JOptionPane.showConfirmDialog(this, "Are you sure you want to Delete this Mark?") == 0) {
                Vector vtM = (Vector) vtMark.get(rscurrent);
                int SubID = Integer.parseInt((vtM.get(3).toString()));
                float mark = Float.parseFloat(vtM.get(7).toString());
                int times = Integer.parseInt(vtM.get(8).toString());
                int status = Integer.parseInt(vtM.get(9).toString());
                int kq = new Database().DeleteMark(StuID, SubID, mark, times, status);
                if (kq != -1) {
                    JOptionPane.showMessageDialog(this, "Delete successful!");
                    loadMark();
                }
            }
        } else {
            JOptionPane.showMessageDialog(this, "choose row want Delete!");
        }

}//GEN-LAST:event_btnDeleteMarkActionPerformed

    private void cbbPaymentTypeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbbPaymentTypeItemStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_cbbPaymentTypeItemStateChanged

    private void btnUpdatePaymentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdatePaymentActionPerformed
        // TODO add your handling code here:
        btnUpdatePayment.setText("Save");
        if (btnUpdatePayment.getText().equals("Save")) {
            boolean valid = validateInformationPayment();
            if (valid) {
                String typeName;
                int typeID = 0;
                Vector vtSub = new Database().loadPaymentType("");
                for (int i = 0; i < vtSub.size(); i++) {
                    typeName = ((Vector) vtSub.get(i)).get(1).toString();
                    if (cbbPaymentType.getSelectedItem().toString().equals(typeName)) {
                        typeID = Integer.parseInt(((Vector) vtSub.get(i)).get(0).toString());
                        break;
                    }
                }
                int courID;
               
                float totalFees = 0;
                Vector vtCount1 = new Database().loadPayment(" where  CRID=" + CRID);
                if (vtCount1.size() > 0) {
                    for (int i = 0; i < vtCount1.size(); i++) {
                        totalFees = Float.parseFloat(((Vector) vtCount1.get(i)).get(2).toString());
                        break;
                    }
                } else {
                    Vector vtCour = new Database().loadCourse(" where CourseID=" + CourID);
                    for (int i = 0; i < vtCour.size(); i++) {
                        courID = Integer.parseInt(((Vector) vtCour.get(i)).get(0).toString());
                        if (courID == CourID) {
                            totalFees = Float.parseFloat(((Vector) vtCour.get(i)).get(2).toString());
                            break;
                        }
                    }
                }
                float paid = 0;
                try {
                    paid = Float.parseFloat(txtPaid.getText());
                } catch (NumberFormatException ex) {
                    JOptionPane.showMessageDialog(this, "Input Paid is Number!");
                    txtPaid.requestFocus();
                }
                float balance = 0;
                 try {
                    balance = Float.parseFloat(txtBalance.getText());
                } catch (NumberFormatException ex) {
                    JOptionPane.showMessageDialog(this, "Input Paid is Number!");
                    txtPaid.requestFocus();
                }
                int Times = Integer.parseInt(txtTimes.getText());
                int Status;
                if (chkSuccessful.isSelected()) {
                    Status = 1;
                } else {
                    Status = 0;
                }
                Vector vtCount = new Database().loadPayment(" where PayTypeID=" + typeID + " and CRID=" + CRID + " and TotalFees=" + totalFees + " and Paid=" + paid + " and Balance=" + balance + " and Times=" + Times + " and Status=" + Status);
                if (vtCount.size() <= 0) {
                    int kq = new Database().UpdatePayment(typeID, CRID, totalFees, paid, balance, Times, Status);
                    if (kq != -1) {
                        JOptionPane.showMessageDialog(this, "update successful!");
                        loadPayment();
                        btnInsertPayment.setText("Insert");
                    } else {
                        btnInsertPayment.setText("Save");
                    }
                } else {
                    JOptionPane.showMessageDialog(this, "Payment was exist!");
                }

            }
        }
    }//GEN-LAST:event_btnUpdatePaymentActionPerformed

    private void tbPaymentMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbPaymentMouseClicked
        // TODO add your handling code here:
        vtPayment = new Database().loadvwPayment(" where CourseID=" + CourID + " and StuID=" + StuID + " order by Times");
        int rscurrent = tbPayment.getSelectedRow();
        if (rscurrent >= 0) {
            Vector vtP = (Vector) vtPayment.get(rscurrent);
            cbbPaymentType.setSelectedItem(vtP.get(6).toString());
            txtPaid.setText(vtP.get(8).toString());
            txtBalance.setText(vtP.get(9).toString());
            txtTimes.setText(vtP.get(10).toString());
            String Status = vtP.get(12).toString();
            if (Status.trim().equals("0")) {
                chkUnsuccessful.setSelected(true);
            } else if (Status.equals("1")) {
                chkSuccessful.setSelected(true);
            }
        }
    }//GEN-LAST:event_tbPaymentMouseClicked

    private void btnRefreshPaymentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshPaymentActionPerformed
        // TODO add your handling code here:
        txtPaid.setText("");
        txtBalance.setText("");
        txtTimes.setText("");
        btnUpdatePayment.setText("Update");
        btnInsertPayment.setText("Insert");
        btnUpdatePayment.setVisible(true);
        cbbPaymentType.setSelectedIndex(0);
    }//GEN-LAST:event_btnRefreshPaymentActionPerformed

    private void btnInsertPaymentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInsertPaymentActionPerformed
        // TODO add your handling code here:
        btnInsertPayment.setText("Save");
        if (btnInsertPayment.getText().equals("Save")) {
            boolean valid = validateInformationPayment1();
            if (valid) {
                String typeName;
                
                /*
                Vector vtSub = new Database().loadPaymentType("");
                for (int i = 0; i < vtSub.size(); i++) {
                    typeName = ((Vector) vtSub.get(i)).get(1).toString();
                    if (cbbPaymentType.getSelectedItem().toString().equals(typeName)) {
                        typeID = Integer.parseInt(((Vector) vtSub.get(i)).get(0).toString());
                        break;
                    }
                }
                 * 
                 */
                int courID;
                float totalFees = 0;
                Vector vtCount1 = new Database().loadPayment(" where  CRID=" + CRID);
                if (vtCount1.size() > 0) {
                    for (int i = 0; i < vtCount1.size(); i++) {
                        totalFees = Float.parseFloat(((Vector) vtCount1.get(i)).get(2).toString());
                        break;
                    }
                } else {
                    Vector vtCour = new Database().loadCourse(" where CourseID=" + CourID);
                    for (int i = 0; i < vtCour.size(); i++) {
                        courID = Integer.parseInt(((Vector) vtCour.get(i)).get(0).toString());
                        if (courID == CourID) {
                            totalFees = Float.parseFloat(((Vector) vtCour.get(i)).get(2).toString());
                            break;
                        }
                    }
                }
                float paid = 0;
                try {
                    paid = Float.parseFloat(txtPaid.getText());
                } catch (NumberFormatException ex) {
                    JOptionPane.showMessageDialog(this, "Input Paid is Number!");
                    txtPaid.requestFocus();
                }


                int Times = 0;
                float total = 0;
                Vector vtCount12 = new Database().loadPayment(" where CRID=" + CRID);
                for (int i = 0; i < vtCount12.size(); i++) {
                    total += Float.parseFloat(((Vector) vtCount12.get(i)).get(3).toString());
                }
                total += paid;
                int Status;
                if (total == totalFees) {
                    Status = 1;
                } else {
                    Status = 0;
                }
                int typeID = 0;
                if (paid == totalFees) {
                    typeID = 1;
                } else {
                    typeID = 2;
                }
                float balance = totalFees - total;
                Vector vtCount = new Database().loadPayment(" where PayTypeID=" + typeID + " and CRID=" + CRID);
                Times = vtCount.size() + 1;

                if (total <= totalFees) {
                    int kq = new Database().addPayment(typeID, CRID, totalFees, paid, balance, Times, Status);

                    if (kq != -1) {
                        JOptionPane.showMessageDialog(this, "insert successful!");
                        loadPayment();
                        btnInsertPayment.setText("Insert");
                    }
                } else {
                    JOptionPane.showMessageDialog(this, "Paid > total Fees!");
                    btnInsertPayment.setText("Save");
                }


                //  }
            }
        }
    }//GEN-LAST:event_btnInsertPaymentActionPerformed

    private void btnDeletePaymentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeletePaymentActionPerformed
        // TODO add your handling code here:
        vtPayment = new Database().loadvwPayment(" where CourseID=" + CourID + " and StuID=" + StuID + " order by Times");
        int rscurrent = tbPayment.getSelectedRow();
        if (rscurrent >= 0) {
            if (JOptionPane.showConfirmDialog(this, "Are you sure you want to Delete this Payment?") == 0) {
                Vector vtM = (Vector) vtPayment.get(rscurrent);
                int PayTypeID = Integer.parseInt((vtM.get(3).toString()));
                int CRID = Integer.parseInt((vtM.get(0).toString()));

                float totalFees = Float.parseFloat(vtM.get(7).toString());
                float paid = Float.parseFloat(vtM.get(8).toString());
                float balance = Float.parseFloat(vtM.get(9).toString());
                int times = Integer.parseInt(vtM.get(10).toString());
                int status = Integer.parseInt(vtM.get(12).toString());
                int kq = new Database().DeletePayment(PayTypeID, CRID, totalFees, paid, balance, times, status);
                if (kq != -1) {
                    JOptionPane.showMessageDialog(this, "Delete successful!");
                    loadPayment();
                }
            }
        } else {
            JOptionPane.showMessageDialog(this, "choose row want Delete!");
        }
    }//GEN-LAST:event_btnDeletePaymentActionPerformed
    /**
     * @param args the command line arguments
     */
    public boolean validateInformationMark() {
        String Subject = cbbSubject.getSelectedItem().toString();
        if (Subject.equals("choose")) {
            JOptionPane.showMessageDialog(this, "you must choose Subject!");
            cbbSubject.requestFocus();
            return false;
        }
        if (txtMark.getText().toString().equals("")) {
            JOptionPane.showMessageDialog(this, "you must input Mark!");
            txtMark.requestFocus();
            return false;
        }

        return true;
    }
     public boolean validateInformationPayment1() {
        
        if (txtPaid.getText().toString().equals("")) {
            JOptionPane.showMessageDialog(this, "you must input Paid!");
            txtPaid.requestFocus();
            return false;
        }
        /*
        if (txtBalance.getText().toString().equals("")) {
        JOptionPane.showMessageDialog(this, "you must input Balance!");
        txtBalance.requestFocus();
        return false;
        }
         *
         */
        return true;
    }
    public boolean validateInformationPayment() {
        String payment = cbbPaymentType.getSelectedItem().toString();
        if (payment.equals("choose")) {
            JOptionPane.showMessageDialog(this, "you must choose Payment Type!");
            cbbPaymentType.requestFocus();
            return false;
        }

        if (txtPaid.getText().toString().equals("")) {
            JOptionPane.showMessageDialog(this, "you must input Paid!");
            txtPaid.requestFocus();
            return false;
        }
        /*
        if (txtBalance.getText().toString().equals("")) {
        JOptionPane.showMessageDialog(this, "you must input Balance!");
        txtBalance.requestFocus();
        return false;
        }
         * 
         */
        return true;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnDeleteMark;
    private javax.swing.JButton btnDeletePayment;
    private javax.swing.JButton btnInsertMark;
    private javax.swing.JButton btnInsertPayment;
    private javax.swing.JButton btnRefreshMark;
    private javax.swing.JButton btnRefreshPayment;
    private javax.swing.JButton btnSignOut;
    private javax.swing.JButton btnUpdateMark;
    private javax.swing.JButton btnUpdatePayment;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JComboBox cbbPaymentType;
    private javax.swing.JComboBox cbbSubject;
    private javax.swing.JRadioButton chkFail;
    private javax.swing.JRadioButton chkPass;
    private javax.swing.JRadioButton chkSuccessful;
    private javax.swing.JRadioButton chkUnsuccessful;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JPanel panAcademic;
    private javax.swing.JPanel panAcademic1;
    private javax.swing.JTable tbMark;
    private javax.swing.JTable tbPayment;
    private javax.swing.JTextField txtBalance;
    private javax.swing.JTextField txtMark;
    private javax.swing.JTextField txtPaid;
    private javax.swing.JTextField txtTime;
    private javax.swing.JTextField txtTimes;
    // End of variables declaration//GEN-END:variables
}
